//
//  DSMainViewController.m
//  IntelligentLock
//
//  Created by yj_zhang on 2019/5/27.
//  Copyright © 2019 yj_zhang. All rights reserved.
//

#import "DSMainViewController.h"

#import "MantisLeaveMessageViewController.h"
#import "PresentChatViewController.h"

#import "MantisDeviceUUID.h"
#import "ChatLeaveMessageView.h"
#import "CommonHeader.h"

static NSString*probeIDStr=@"probeId";
static NSString*userIDStr=@"userId";


@interface DSMainViewController ()

@property(nonatomic,strong)ChatLeaveInputView*probeView;//探头view
@property(nonatomic,strong)ChatLeaveInputView*userView;//用户view
@end

@implementation DSMainViewController

-(void)viewWillAppear:(BOOL)animated{
    [super viewWillAppear:animated];
    self.tabBarController.tabBar.hidden = YES;
    
}

- (void)viewDidLoad {
    [super viewDidLoad];
    [self setNavigationBarStyle:BarTint_Default];
    self.view.backgroundColor =[UIColor whiteColor];
    NSString*probeId =[[NSUserDefaults standardUserDefaults]objectForKey:probeIDStr];
    NSString*userId=[[NSUserDefaults standardUserDefaults]objectForKey:userIDStr];
    
    
    NSArray*arr=@[@{@"name":@"* 探头",@"place":@"请输入探头id"}];
    for (int i=0; i<arr.count; i++) {
        ChatLeaveInputView*inputView =[ChatLeaveInputView new];
        [self.view addSubview:inputView];
        NSDictionary*dic=arr[i];
        [inputView reloadViewWithDic:dic];
        
        if (i==0) {
            self.probeView=inputView;
            self.probeView.inputView.text=probeId;
        }else{
            self.userView=inputView;
            self.userView.inputView.text=userId;
        }
        
        CGFloat inputHeight=adaptWidth750(52*2);
        [inputView mas_makeConstraints:^(MASConstraintMaker *make) {
            make.left.right.mas_equalTo(0);
            make.top.mas_equalTo(inputHeight*i+150);
            make.height.mas_equalTo(inputHeight);
        }];
    }
    
    
    
    UIButton *testWebBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [testWebBtn setTitle:@"登录进入聊天" forState:UIControlStateNormal];
    [testWebBtn setTitleColor:KAppMainColor forState:UIControlStateNormal];
    [self.view addSubview:testWebBtn];
    [testWebBtn mas_makeConstraints:^(MASConstraintMaker *make) {
        make.center.equalTo(self.view);
    }];
    [testWebBtn addTarget:self action:@selector(rightAction:) forControlEvents:UIControlEventTouchUpInside];
    
}
//开始登录
-(void)startLogin{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginSucess:) name:KnoticeLoginSucess object:nil];
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(loginFail:) name:KnoticeLoginFail object:nil];
    
}

-(void)loginSucess:(NSNotification*)notice{
    NSLog(@"登录成功");
    
}

-(void)loginFail:(NSNotification*)notice{
    NSLog(@"登录失败");
    
}

-(void)rightAction:(UIButton *)rightBtn{
   
  //半屏效果
    PresentChatViewController*presentVC = [PresentChatViewController new];
    presentVC.userModel=self.userModel;
    presentVC.probeModel=self.probeModel;
    
    NSMutableArray*imgArr = [NSMutableArray new];
    [imgArr addObject:[UIImage imageNamed:@"爱心"]];
    [imgArr addObject:[UIImage imageNamed:@"比心"]];
    presentVC.imgArr=imgArr;
    presentVC.loadingText=@"客服211与您对话";
    
    [presentVC showCurrentVC:self.navigationController];
}




- (BOOL)shouldAutorotate{
    return NO;
}

- (UIInterfaceOrientationMask)supportedInterfaceOrientations{
    return UIInterfaceOrientationMaskPortrait;
}

- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation{
    return UIInterfaceOrientationPortrait;
}



@end
